package com.web.dto;

import com.web.model.UserInfo;
import java.io.Serializable;
import org.springframework.util.StringUtils;

/**
 * @author yangguanzan
 * @date 9/23/21
 * @description
 */
public class UserInfoDTO implements Serializable {
    private static final long serialVersionUID = 2176859564503162717L;
     /**
     *用户账号
     */
    private String username;

    /**
     * 昵称
     */
    private String nickName;

    /**
     *密码
     */
    private String password;

    /**
     * 确认密码
     */
    private String passwordConfirm;

    /**
     *邮箱
     */
    private String email;

    /**
     *手机号
     */
    private String phone;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPasswordConfirm() {
        return passwordConfirm;
    }

    public void setPasswordConfirm(String passwordConfirm) {
        this.passwordConfirm = passwordConfirm;
    }

    /**
     * 验证两次密码是否正确
     * @return
     */
    public boolean checkTwoPassword(){
        //非空判断，空则返回错误
        if(StringUtils.isEmpty(password)){
            return false;
        }
        if(StringUtils.isEmpty(passwordConfirm)){
            return false;
        }
        //非空判断，不为空则验证两次密码是否一致
        return password.equals(passwordConfirm);
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public String toString() {
        return "UserInfoDTO{" +
            "username='" + username + '\'' +
            ", nickName='" + nickName + '\'' +
            ", password='" + password + '\'' +
            ", passwordConfirm='" + passwordConfirm + '\'' +
            ", email='" + email + '\'' +
            ", phone='" + phone + '\'' +
            '}';
    }

    public UserInfo toUserInfo(){
        UserInfo userInfo = new UserInfo();
        userInfo.setNickName(this.getNickName());
        userInfo.setPassword(this.getPassword());
        userInfo.setEmail(this.getEmail());
        userInfo.setPhone(this.getPhone());
        userInfo.setUsername(this.getUsername());
        return userInfo;
    }


}
